import { _decorator, UIOpacity, EventTarget } from "cc";
import { BaseView } from "../../rxjs/cc3/BaseView";
const { ccclass, property } = _decorator;

/**
 * 重写setItem就可以使用了,data就是fetchDataForKey里面addDataFunc传入数组的对应一行数据,用于刷新表现
 */
@ccclass
export default class dynamicScrollViewItem extends BaseView {

    eventTarget: EventTarget = null;

    data: any = null;

    eventPrefix: string = 'defaultDSVevent';

    initOnce() {
        // this.log('请在子类实现initOnce函数以在实例化之后进行初始化，仅一次');
    }

    init() {
        // this.log('请在子类实现init函数以初始化或者重置一个dynamicScrollViewItem');
    }

    setItem(data) {
        // cc.log('请在子类实现setItem函数以显示');
        this.data = data;
    }

    appear(param) {
        this.node.getComponent(UIOpacity).opacity = 255;
        this.eventTarget?.emit(this.eventPrefix + '_refresh', { rank: this.data.rank });
    }

    disappear() {
        this.node.getComponent(UIOpacity).opacity = 0;
    }

    //在刷新一个行时调用
    emitEventRefresh() {
        this.eventTarget?.emit(this.eventPrefix + '_refresh', { rank: this.data.rank });
    }

}
